package com.wbp.cms.core.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.common.base.Preconditions;
import com.wbp.cms.client.common.domain.OrganizationDO;
import com.wbp.cms.client.common.query.OrganizationQuery;
import com.wbp.cms.client.common.service.OrganizationService;
import com.wbp.cms.client.result.Result;
import com.wbp.cms.core.dao.OrganizationDAO;


/**
 * @Description:
 * @Department:
 * @author andy.lhc
 * @date 2016年3月9日 下午2:37:56
 */
@Service("organizationService")
public class OrganizationServiceImpl implements OrganizationService {

  /**
   * 
   */
  private static final long serialVersionUID = 6290502407128447212L;
  @Resource(name = "organizationDAO")
  private OrganizationDAO organizationDAO;

   
  @Override
  public Result<Long> addOrganization(OrganizationDO organizationDO) {
     Preconditions.checkArgument(organizationDO !=null ,"organizationDO不能为null") ;
     return Result.buildSuccess(  organizationDAO.insert(organizationDO) ) ;
  }

   
  @Override
  public Result<Boolean> modifyOrganization(OrganizationDO organizationDO) {
    Preconditions.checkArgument(organizationDO !=null ,"organizationDO不能为null") ;
    Preconditions.checkArgument(organizationDO.getId() !=null && organizationDO.getId() > 0 ,"organizationDO.id应>0") ;
    return Result.buildSuccess(  organizationDAO.update(organizationDO) > 0 ) ;
  }

  
  @Override
  public Result<OrganizationDO> queryOrganizationById(Long organizationId) {
    
    Preconditions.checkNotNull(organizationId ,"organizationId:"+organizationId+",不能为null") ;
    Preconditions.checkArgument(organizationId >0  ,"organizationId:"+organizationId+",应 > 0 ") ;
    OrganizationDO  orgDO = organizationDAO.load(organizationId) ;
    return Result.buildSuccess( orgDO ) ;
  }

   
  @Override
  public  List<OrganizationDO>  queryOrganization(OrganizationQuery organizationQuery) {
    Preconditions.checkNotNull(organizationQuery, "参数不能为null") ; 
    
    return   organizationDAO.query(organizationQuery)  ;
  }

  public  int  queryOrganizationCount(OrganizationQuery organizationQuery){
    Preconditions.checkNotNull(organizationQuery, "参数不能为null") ; 
    return  this.organizationDAO.queryCount(organizationQuery) ;
  }

   
  @Override
  public List<OrganizationDO> queryChildOrganizations(Long orgId) {
    Preconditions.checkArgument(orgId >0  ,"orgId:"+orgId+",应 > 0 ") ;
    return  this.organizationDAO.queryChildOrganization(orgId) ;
  }



}
